use std::fmt::{Debug, Display};

fn main() {
    // vec![1] 未实现Display
    // let s = S(vec![1]);

    let rectangle = Rectangle {
        length: 3.0,
        height: 4.0,
    };
    let _triangle = Triangle {
        length: 3.0,
        height: 4.0,
    };

    print_debug(&rectangle);
    println!("Area:{}", area(&rectangle));

    // print_debug(&_triangle);
    // println!("Area:{}", area(&_triangle));
}

fn printer<T: Display>(t: T) {
    println!("{}", t);
}

struct S<T: Display>(T);

trait HasArea {
    fn area(&self) -> f64;
}

impl HasArea for Rectangle {
    fn area(&self) -> f64 {
        self.length * self.length
    }
}
#[derive(Debug)]
struct Rectangle {
    length: f64,
    height: f64,
}

#[allow(dead_code)]
struct Triangle {
    length: f64,
    height: f64,
}

fn print_debug<T: Debug>(t: &T) {
    println!("{:?}", t);
}

fn area<T: HasArea>(t: &T) -> f64 {
    t.area()
}
